package com.ruoyi.project.system.joinus.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PageQuery;
import com.ruoyi.framework.web.page.TableData;
import com.ruoyi.project.system.joinus.domain.Joinus;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.joinus.mapper.JoinusMapper;
import com.ruoyi.project.system.joinus.service.IJoinusService;

/**
 * joinusService业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-17
 */
@Service
public class JoinusServiceImpl implements IJoinusService
{
    @Autowired
    private JoinusMapper joinusMapper;

    /**
     * 查询joinus
     * 
     * @param id joinus主键
     * @return joinus
     */
    @Override
    public Joinus selectById(Long id)
    {
        return joinusMapper.selectById(id);
    }

    /**
     * 查询joinus列表
     * 
     * @param joinus joinus
     * @return joinus
     */
    @Override
    public TableData<Joinus> selectList(Joinus joinus, PageQuery pageQuery)
    {
        LambdaQueryWrapper<Joinus> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNoneBlank(joinus.getYouname()), Joinus::getYouname,joinus.getYouname())
        .like(StringUtils.isNoneBlank(joinus.getContactInfo()), Joinus::getContactInfo,joinus.getContactInfo());
        Page<Joinus> page = joinusMapper.selectPage(pageQuery.build(), lqw);
        return TableData.build(page);
    }

    /**
     * 新增joinus
     * 
     * @param joinus joinus
     * @return 结果
     */
    @Override
    public int insert(Joinus joinus)
    {
        joinus.setCreateTime(DateUtils.getNowDate());
        return joinusMapper.insert(joinus);
    }

    /**
     * 修改joinus
     * 
     * @param joinus joinus
     * @return 结果
     */
    @Override
    public int update(Joinus joinus)
    {
        joinus.setUpdateTime(DateUtils.getNowDate());
        return joinusMapper.updateById(joinus);
    }

    /**
     * 批量删除joinus
     * 
     * @param ids 需要删除的joinus主键
     * @return 结果
     */
    @Override
    public int deleteByIds(String ids)
    {
        List<String> collect = Arrays.stream(ids.split(",")).collect(Collectors.toList());
        return joinusMapper.deleteBatchIds(collect);
    }

    /**
     * 删除joinus信息
     * 
     * @param id joinus主键
     * @return 结果
     */
    @Override
    public int deleteAJoinusById(Long id)
    {
        return joinusMapper.deleteById(id);
    }
}
